// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless;

public sealed partial class NestedSortValue
{
	[JsonInclude, JsonPropertyName("filter")]
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? Filter { get; set; }
	[JsonInclude, JsonPropertyName("max_children")]
	public int? MaxChildren { get; set; }
	[JsonInclude, JsonPropertyName("nested")]
	public Elastic.Clients.Elasticsearch.Serverless.NestedSortValue? Nested { get; set; }
	[JsonInclude, JsonPropertyName("path")]
	public Elastic.Clients.Elasticsearch.Serverless.Field Path { get; set; }
}

public sealed partial class NestedSortValueDescriptor<TDocument> : SerializableDescriptor<NestedSortValueDescriptor<TDocument>>
{
	internal NestedSortValueDescriptor(Action<NestedSortValueDescriptor<TDocument>> configure) => configure.Invoke(this);

	public NestedSortValueDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> FilterDescriptorAction { get; set; }
	private int? MaxChildrenValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.NestedSortValue? NestedValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor<TDocument> NestedDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor<TDocument>> NestedDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field PathValue { get; set; }

	public NestedSortValueDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Filter(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> MaxChildren(int? maxChildren)
	{
		MaxChildrenValue = maxChildren;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Nested(Elastic.Clients.Elasticsearch.Serverless.NestedSortValue? nested)
	{
		NestedDescriptor = null;
		NestedDescriptorAction = null;
		NestedValue = nested;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Nested(Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor<TDocument> descriptor)
	{
		NestedValue = null;
		NestedDescriptorAction = null;
		NestedDescriptor = descriptor;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Nested(Action<Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor<TDocument>> configure)
	{
		NestedValue = null;
		NestedDescriptor = null;
		NestedDescriptorAction = configure;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Path(Elastic.Clients.Elasticsearch.Serverless.Field path)
	{
		PathValue = path;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Path<TValue>(Expression<Func<TDocument, TValue>> path)
	{
		PathValue = path;
		return Self;
	}

	public NestedSortValueDescriptor<TDocument> Path(Expression<Func<TDocument, object>> path)
	{
		PathValue = path;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (MaxChildrenValue.HasValue)
		{
			writer.WritePropertyName("max_children");
			writer.WriteNumberValue(MaxChildrenValue.Value);
		}

		if (NestedDescriptor is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedDescriptor, options);
		}
		else if (NestedDescriptorAction is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor<TDocument>(NestedDescriptorAction), options);
		}
		else if (NestedValue is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedValue, options);
		}

		writer.WritePropertyName("path");
		JsonSerializer.Serialize(writer, PathValue, options);
		writer.WriteEndObject();
	}
}

public sealed partial class NestedSortValueDescriptor : SerializableDescriptor<NestedSortValueDescriptor>
{
	internal NestedSortValueDescriptor(Action<NestedSortValueDescriptor> configure) => configure.Invoke(this);

	public NestedSortValueDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> FilterDescriptorAction { get; set; }
	private int? MaxChildrenValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.NestedSortValue? NestedValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor NestedDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor> NestedDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field PathValue { get; set; }

	public NestedSortValueDescriptor Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public NestedSortValueDescriptor Filter(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public NestedSortValueDescriptor Filter(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	public NestedSortValueDescriptor MaxChildren(int? maxChildren)
	{
		MaxChildrenValue = maxChildren;
		return Self;
	}

	public NestedSortValueDescriptor Nested(Elastic.Clients.Elasticsearch.Serverless.NestedSortValue? nested)
	{
		NestedDescriptor = null;
		NestedDescriptorAction = null;
		NestedValue = nested;
		return Self;
	}

	public NestedSortValueDescriptor Nested(Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor descriptor)
	{
		NestedValue = null;
		NestedDescriptorAction = null;
		NestedDescriptor = descriptor;
		return Self;
	}

	public NestedSortValueDescriptor Nested(Action<Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor> configure)
	{
		NestedValue = null;
		NestedDescriptor = null;
		NestedDescriptorAction = configure;
		return Self;
	}

	public NestedSortValueDescriptor Path(Elastic.Clients.Elasticsearch.Serverless.Field path)
	{
		PathValue = path;
		return Self;
	}

	public NestedSortValueDescriptor Path<TDocument, TValue>(Expression<Func<TDocument, TValue>> path)
	{
		PathValue = path;
		return Self;
	}

	public NestedSortValueDescriptor Path<TDocument>(Expression<Func<TDocument, object>> path)
	{
		PathValue = path;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (MaxChildrenValue.HasValue)
		{
			writer.WritePropertyName("max_children");
			writer.WriteNumberValue(MaxChildrenValue.Value);
		}

		if (NestedDescriptor is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedDescriptor, options);
		}
		else if (NestedDescriptorAction is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.NestedSortValueDescriptor(NestedDescriptorAction), options);
		}
		else if (NestedValue is not null)
		{
			writer.WritePropertyName("nested");
			JsonSerializer.Serialize(writer, NestedValue, options);
		}

		writer.WritePropertyName("path");
		JsonSerializer.Serialize(writer, PathValue, options);
		writer.WriteEndObject();
	}
}